<template>
	<public-view navType="other" navTitle="添加银行卡">
		<view class="content">
			<view class="password-input-box f-s-24 flex a-i-c">
				<view class="title">
					姓名
				</view>
				<input class="ihnput" v-model="name" style="flex: 1;" type="text" placeholder="请输入姓名">
			</view>
			<view class="password-input-box f-s-24 flex a-i-c">
				<view class="title">
					手机号
				</view>
				<input class="ihnput" v-model="mobile" style="flex: 1;" type="number" placeholder="请输入手机号">
			</view>
			<view class="password-input-box f-s-24 flex a-i-c">
				<view class="title">
					开户行
				</view>
				<input class="ihnput " v-model="open_bank" style="flex: 1;" type="text" placeholder="请输入开户行">
			</view>
			<view class="password-input-box f-s-24 flex a-i-c">
				<view class="title">
					卡号
				</view>
				<input class="ihnput " v-model="bank_card_number" style="flex: 1;" type="number" placeholder="请输入银行卡号">
			</view>
			<view class="password-input-box f-s-24 flex a-i-c">
				<view class="title">
					银行卡类型
				</view>
				<input class="ihnput " v-model="bank" style="flex: 1;" type="text" placeholder="请输入银行卡类型">
			</view>
			<view class="enter-btn all-center f-s-30 color-fff" @click="saveBankCard">
				确认添加
			</view>
		</view>
	</public-view>
</template>

<script>
	import {goBack} from "@/nav.js"
	export default {
		data() {
			return {
				name:"",
				mobile:"",
				open_bank:"",
				bank_card_number:"",
				bank:"",
				id:""
			};
		},
		onLoad(options) {
			let bank = null
			console.log(options)
			if(options.bank){
				bank = JSON.parse(options.bank)
				this.name = bank.name
				this.mobile = bank.mobile
				this.bank = bank.bank
				this.open_bank = bank.open_bank
				this.id = bank.id
				this.bank_card_number = bank.bank_card_number
			}
		},
		methods:{
			saveBankCard(){
				let that = this
				if(that.name === ''){
					uni.showToast({
						title:"请输入姓名"
					})
					return
				}
				if(that.mobile === ''){
					uni.showToast({
						title:"请输入手机号"
					})
					return
				}
				if(that.bank_card_number === ''){
					uni.showToast({
						title:"请输入银行卡号"
					})
					return
				}
				if(that.open_bank === ''){
					uni.showToast({
						title:"请输入开户行"
					})
					return
				}
				if(that.bank === ''){
					uni.showToast({
						title:"请输入银行卡类型"
					})
					return
				}
				let data = {
					name:that.name,
					mobile:that.mobile,
					bank_card_number:that.bank_card_number,
					open_bank:that.open_bank,
					bank:that.bank
				}
				if(that.id !== ''){
					data.id = that.id
				}
				that.util.postRequest({
					url:"v1/user_bank_card/edit",
					data:data
				}).then(res=>{
					console.log(res)
					uni.showToast({
						title:"保存成功",
						duration:2500
					})
					let timeout=setTimeout(()=>{
						clearTimeout(timeout)
						goBack()
					},2500)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.enter-btn{
		width: 702upx;
		height: 96upx;
		background: #2567F3;
		border-radius: 128upx;
		margin-top: 34upx;
	}
	.password-input-box{
		width: 100%;
		padding: 42upx 40upx;
		background: #FFFFFF;
		border-radius: 20px;
		font-weight: bold;
		margin-bottom: 20upx;
		.ihnput{
			line-height: 34upx;
		}
		.title{
			line-height: 40upx;
			margin-right: 36upx;
		}
	}
	.content{
		width: 750upx;
		padding: 42upx 30upx;
	}
</style>
